﻿using Furion;
using Furion.DatabaseAccessor;
using Gear.Core;
using Gear.Core.Locator.TenantDbContext;
using Gear.EntityFramework.Core.TenantDbContext;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Gear.EntityFramework.Core
{
    [AppStartup(700)]
    public sealed class DataBaseStartup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            // EF配置数据库上下文，支持多个数据库
            services.AddDatabaseAccessor(options =>
            {

                services.AddDatabaseAccessor(options =>
                {
                    options.CustomizeMultiTenants("this is a placeholder for the TenantId");// 启用自定义多租户类型，有一个默认参数，配置多租户表字段名
                    #region 配置默认数据库

                    options.AddDbPool<MySqlDbContext>(DbProvider.MySql);

                    #endregion

                    #region 配置多个数据库，多个数据库必须指定数据库上下文定位器

                    //oracle
                    //options.AddDbPool<OracleDbContext, OracleDbContextLocator>(DbProvider.Oracle);
                    //sqlserver
                    options.AddDbPool<MsSqlDbContext, MsSqlDbContextLocator>(DbProvider.SqlServer);

                    #endregion

                    #region 配置多租户数据库上下文

                    options.AddDbPool<MultiTenantsDbContext, MultiTenantDbContextLocator>();

                    #endregion

                }, "Gear.Database.Migrations");



            });

        }
    }
}